<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<cl-export-btn :columns="Table?.columns" />
			<cl-flex1 />
			<!-- 条件搜索 -->
			<cl-search ref="Search" />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" setup>
defineOptions({
	name: "order-share",
});

import { useCrud, useTable, useUpsert, useSearch } from "@cool-vue/crud";
import { useCool } from "/@/cool";
import { useI18n } from "vue-i18n";
import { reactive } from "vue";

const { service } = useCool();
const { t } = useI18n();

// 选项
const options = reactive({
	shareStatus: [
		{ label: t("待分账"), value: 0 },
		{ label: t("已分账"), value: 1 },
		{ label: t("分账失败"), value: 2 },
		{ label: t("已退款"), value: 3 },
	],
});

// cl-upsert
const Upsert = useUpsert({
	items: [
		{
			label: t("选择系统订单"),
			prop: "sysOrderId",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("订单号"),
			prop: "orderNo",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
			required: true,
		},
		{
			label: t("分账状态"),
			prop: "shareStatus",
			component: { name: "el-radio-group", options: options.shareStatus },
			value: 0,
			required: true,
		},
		{
			label: t("分账金额"),
			prop: "shareAmount",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
			required: true,
		},
		{
			label: t("备注"),
			prop: "remark",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("选择微信支付商户号"),
			prop: "mchId",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("选择微信支付订单号"),
			prop: "transactionId",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("分账接收方列表"),
			prop: "receiverList",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("分账详情"),
			prop: "shareDetail",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
		{
			label: t("回调内容"),
			prop: "callbackContent",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
		},
	],
});

// cl-table
const Table = useTable({
	columns: [
		// { type: "selection" },
		{ label: t("分账订单ID"), prop: "id", minWidth: 100 },
		
		{ label: t("城市"), prop: "cityName", minWidth: 120 },
		{ label: t("店铺"), prop: "shopName", minWidth: 120 },
		{ label: t("用户"), prop: "userName", minWidth: 120 },
		{ label: t("用户电话"), prop: "userPhone", minWidth: 120 },
		{ label: t("订单金额"), prop: "orderAmount", minWidth: 120 },
		{
			label: t("分账状态"),
			prop: "shareStatus",
			minWidth: 120,
			dict: options.shareStatus,
		},
		{ label: t("系统订单ID"), prop: "sysOrderId", minWidth: 80 },
		{ label: t("订单号"), prop: "orderNo", minWidth: 120 },
		// { label: t("分账金额"), prop: "shareAmount", minWidth: 120 },
		// { label: t("备注"), prop: "remark", minWidth: 120 },
		// { label: t("微信支付商户号"), prop: "mchId", minWidth: 120 },
		{ label: t("微信支付订单号"), prop: "transactionId", minWidth: 120 },
		// { label: t("分账接收方列表"), prop: "receiverList", minWidth: 120 },
		// { label: t("分账详情"), prop: "shareDetail", minWidth: 120 },
		// { label: t("回调内容"), prop: "callbackContent", minWidth: 120 },
		// {
		// 	label: t("创建时间"),
		// 	prop: "createTime",
		// 	minWidth: 170,
		// 	sortable: "desc",
		// 	component: { name: "cl-date-text" },
		// },
		// {
		// 	label: t("更新时间"),
		// 	prop: "updateTime",
		// 	minWidth: 170,
		// 	sortable: "custom",
		// 	component: { name: "cl-date-text" },
		// },
		// { type: "op", buttons: ["edit", "delete"] },
	],
});

// cl-search
const Search = useSearch();

// cl-crud
const Crud = useCrud(
	{
		service: service.order.share,
		async onRefresh(params, { next, done, render }) {
			params.shareStatus = 1;
			Crud.value.params.shareStatus = 1;
            const { list } = await next(params);
			// 渲染数据
			render(list);
		}
	},
	(app) => {
		app.refresh();
	},
);

// 刷新
function refresh(params?: any) {
	Crud.value?.refresh(params);
}
</script>
